﻿//------------------------------------------------------------------------------
// <copyright file="SimplifiedPropertyDefinition.cs" company="CommerceServer.net, Inc">
//    (c) 2012 CommerceServer.net, Inc. and its affiliates. All rights reserved.
// </copyright>
// <summary></summary>
//------------------------------------------------------------------------------ 
namespace CommerceServerContrib.CodeGeneration
{
    using CommerceServer.Foundation.Definitions;
    using System;

    public class SimplifiedPropertyDefinition : MarshalByRefObject
    {
        public SimplifiedPropertyDefinition()
        {
        }

        public SimplifiedPropertyDefinition(PropertyDefinition propertyDefinition)
        {
            this.Name = Utilities.CleanName(propertyDefinition.Name);
            this.DesignTimeType = propertyDefinition.PropertyType.Value.ToString();
            this.RuntimeType = this.ConvertType(this.DesignTimeType);
            this.WeaklyTypedName = propertyDefinition.Name;
        }

        public string Name { get; set; }

        public string RuntimeType { get; set; }

        public string DesignTimeType { get; set; }

        public string WeaklyTypedName { get; set; }

        public string ConvertType(string type)
        {
            switch (type)
            {
                case "PASSWORD":
                case "SITETERM":
                case "nvarchar":
                case "image":
                case "timestamp":
                case "String":
                case "STRING":
                case "Text":
                case "Enumeration":
                case "FilePath":
                case "RichText":
                case "Url":
                    return "string";
                case "bit":
                case "BOOL":
                case "Boolean":
                    return "bool?";
                case "money":
                case "Currency":
                case "Decimal":
                    return "decimal?";
                case "int":
                case "NUMBER":
                case "BigInteger":
                case "Integer":
                    return "int?";
                case "FLOAT":
                case "Float":
                    return "float?";
                case "Double":
                    return "double?";
                case "UniqueIdentifier":
                case "uniqueidentifier":
                    return "Guid?";
                case "Date":
                case "Time":
                case "DATETIME":
                case "DateTime":
                case "datetime":
                    return "DateTime?";
                default:
                    break;
            }

            return type;
        }
    }
}
